package src;

import java.time.LocalDateTime;
import java.util.Map;

// 抽象角色基类，包含通用菜单逻辑
public abstract class BaseRole extends User {
    public BaseRole(String userId, String username, String passwordHash, String role, LocalDateTime registrationTime, String phoneNumber) {
        super(userId, username, passwordHash, role, registrationTime, phoneNumber);
    }

    // 抽象方法：子类实现具体菜单选项
    public abstract void showMenu();

    // 通用输入循环
    protected void menuLoop(String menuTitle, Map<Integer, Runnable> options) {
        while (true) {
            System.out.println("\n=== " + menuTitle + " ===");
            options.forEach((k, v) -> System.out.println(k + ". " + getOptionName(k))); // 需补充选项名称映射
            System.out.print("请选择操作: ");
            int choice = Input.getValidIntInput(0, options.size());
            if (choice == 0) {
                System.out.println("已退出菜单。");
                return;
            }
            options.get(choice).run();
        }
    }

    // 需子类实现选项名称映射
    protected abstract String getOptionName(int choice);
}
